/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;

import Modelo.Clases.*;
import Modelo.Modelo;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author cltsmalc
 */
public class AdministradorJPanel extends javax.swing.JPanel {

    /**
     * Creates new form AdministradorJPanel
     */
    
     
    String cedula, nombre,estado,apellido, usuario, clave,genero;
    ArrayList lista = new ArrayList();
    int filaSeleccionada = 0;

    public AdministradorJPanel() {
        initComponents();
    }
    
    public AdministradorJPanel(int width, int height) {
        initComponents();
        
        this.setSize(width, height);
        this.setVisible(true);
        
        
        List<Administrador> lista = Modelo.consultarAdministradores();
         
         for(int i = 0 ; i < lista.size() ; i++){
         
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
             this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
             this.jTable1.setValueAt(lista.get(i).getUsuario(), i, 2);
             this.jTable1.setValueAt(lista.get(i).getClave(), i, 3);
             this.jTable1.setValueAt(lista.get(i).getCedula(), i, 4);
             this.jTable1.setValueAt(lista.get(i).getEstado(), i, 5);
         }
        
                
        
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jEImagePanel1 = new recursos.JEImagePanel();
        jButton1 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField6 = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(923, 575));

        jEImagePanel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/magic-wind-blue.jpg"))); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Add.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "activo", "inactivo", "eliminado"}));

        jLabel7.setText("Estado:");

        jLabel8.setText("Nacimiento:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "masculino", "femenino"}));

        jLabel6.setText("Genero:");

        jLabel5.setText("Clave:");

        jLabel4.setText("Usuario:");

        jLabel3.setText("Cedula:");

        jTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField3KeyTyped(evt);
            }
        });

        jLabel2.setText("Apellido:");

        jTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField2KeyTyped(evt);
            }
        });

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                jTextField1KeyTyped(evt);
            }
        });

        jLabel1.setText("Nombre:");

        jLabel9.setBackground(new java.awt.Color(204, 255, 153));
        jLabel9.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel9.setText("Ingreso de  Administrador");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Trash_Delete.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Nombre", "Apellido", "Usuario", "Clave", "Cedula", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, true, true, true, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextField6.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField6KeyReleased(evt);
            }
        });

        jButton4.setBackground(new java.awt.Color(255, 255, 255));
        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/buscar.png"))); // NOI18N

        javax.swing.GroupLayout jEImagePanel1Layout = new javax.swing.GroupLayout(jEImagePanel1);
        jEImagePanel1.setLayout(jEImagePanel1Layout);
        jEImagePanel1Layout.setHorizontalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(46, 46, 46)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jTextField1)
                                    .addComponent(jTextField2)
                                    .addComponent(jTextField3)
                                    .addComponent(jTextField4)
                                    .addComponent(jTextField5)
                                    .addComponent(jDateChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jComboBox1, 0, 168, Short.MAX_VALUE)))))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jButton1)))
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 69, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 543, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(127, 127, 127)
                        .addComponent(jButton2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 363, Short.MAX_VALUE)
                        .addComponent(jButton3)))
                .addGap(37, 37, 37))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                .addContainerGap(485, Short.MAX_VALUE)
                .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 287, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(93, 93, 93))
        );
        jEImagePanel1Layout.setVerticalGroup(
            jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(26, 26, 26)))
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jEImagePanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(jEImagePanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel8)
                                .addGap(46, 46, 46))
                            .addGroup(jEImagePanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jDateChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(47, 47, 47)))
                .addGroup(jEImagePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addGap(107, 107, 107))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jEImagePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

try{
    
    
    
        Administrador administrador = new Administrador(jTextField1.getText(), 
                jTextField2.getText(), jTextField4.getText(), jTextField5.getText(), 
                jTextField3.getText(), jComboBox1.getSelectedItem().toString(),
                jDateChooser1.getDate(), 1, jComboBox2.getSelectedItem().toString());

        Modelo.guardar(administrador);
        
         initComponents();
         
         List<Administrador> lista = Modelo.consultarAdministradores();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         //this.jTable1.setVisible(false);
         
         for(int i = 0 ; i < lista.size() ; i++){
         
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
             this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
             this.jTable1.setValueAt(lista.get(i).getUsuario(), i, 2);
             this.jTable1.setValueAt(lista.get(i).getClave(), i, 3);
             this.jTable1.setValueAt(lista.get(i).getCedula(), i, 4);
             this.jTable1.setValueAt(lista.get(i).getEstado(), i, 5);
         }
        // this.jTable1.setVisible(true);
         this.setVisible(true);
         JOptionPane.showMessageDialog(null,"Guardado correctamente");
        }catch(Exception e){
        JOptionPane.showMessageDialog(null,"Error al guardar datos");
}
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField3KeyTyped
// TODO add your handling code here:
        char caracter = evt.getKeyChar();

        // Verificar si la tecla pulsada no es un digito
        if (((caracter < '0')
                || (caracter > '9') || jTextField3.getText().length() >= 10)
                && (caracter != '\b' /*
                 * corresponde a BACK_SPACE
                 */)) {
            evt.consume();  // ignorar el evento de teclado
        }
    }//GEN-LAST:event_jTextField3KeyTyped

    private void jTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField2KeyTyped
// TODO add your handling code here:
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField1.getText().length() >= 10) {
            evt.consume();

        }
    }//GEN-LAST:event_jTextField2KeyTyped

    private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyTyped
// TODO add your handling code here:
        /**
         * ********** valida que sea solo letras************
         */
        char caracter = evt.getKeyChar();
        if (Character.isDigit(caracter) == true || jTextField1.getText().length() >= 10) {
            evt.consume();

        }
    }//GEN-LAST:event_jTextField1KeyTyped

    public void habilitaInicio(){
        jButton2.setEnabled(true);
        jButton3.setEnabled(true);
    }
    
    
    int bandera = 0 ;
    int id = -1 ;
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed

        try{
            if(bandera == 0 ){
        String cedula = (String)   this.jTable1.getValueAt(jTable1.getSelectedRow(), 4);
        Administrador a = Modelo.consultarAdministrador(cedula);
        if(a != null){
            this.id = a.getIdAdministrador() ;
            this.jTextField1.setText(a.getNombre());
            this.jTextField2.setText(a.getApellido());
            this.jTextField3.setText(a.getCedula());
            this.jTextField4.setText(a.getUsuario());
            this.jTextField5.setText(a.getClave());
            if(a.getGenero().equalsIgnoreCase("masculino")){
            this.jComboBox1.setSelectedIndex(0);
            }
            if(a.getGenero().equalsIgnoreCase("femenino")){
            this.jComboBox1.setSelectedIndex(1);
            }
            
            this.jDateChooser1.setDate(a.getFechaNacimiento());
            if(a.getEstado().equalsIgnoreCase("eliminado")){
            this.jComboBox2.setSelectedIndex(2);
                    }
            if(a.getEstado().equalsIgnoreCase("inactivo")){
            this.jComboBox2.setSelectedIndex(1);
                    }
            if(a.getEstado().equalsIgnoreCase("activo")){
            this.jComboBox2.setSelectedIndex(0);
                    }
            this.jLabel9.setText("Modificar");
            
            
         bandera = 1 ;
         jButton1.setEnabled(false);
         jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/guardar.png")));
            
        }else{
            JOptionPane.showMessageDialog(null,"Error al cargar datos");
    }
        
            }else{
            
            Administrador administrador = Modelo.consultarAdministrador(this.id);
            administrador.setNombre(jTextField1.getText());
            administrador.setApellido(jTextField2.getText());
            administrador.setCedula(jTextField3.getText());
            administrador.setUsuario(jTextField4.getText());
            administrador.setClave(jTextField5.getText());
            administrador.setGenero( jComboBox1.getSelectedItem().toString());
            administrador.setFechaNacimiento( jDateChooser1.getDate());
            administrador.setEstado( jComboBox2.getSelectedItem().toString());
            
            
            
            Modelo.actualizar(administrador);
            
              initComponents();
         
         List<Administrador> lista = Modelo.consultarAdministradores();
         this.setVisible(false);
         this.removeAll();
         initComponents();
         
         //this.jTable1.setVisible(false);
         
         for(int i = 0 ; i < lista.size() ; i++){
         
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
             this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
             this.jTable1.setValueAt(lista.get(i).getUsuario(), i, 2);
             this.jTable1.setValueAt(lista.get(i).getClave(), i, 3);
             this.jTable1.setValueAt(lista.get(i).getCedula(), i, 4);
             this.jTable1.setValueAt(lista.get(i).getEstado(), i, 5);
         }
        // this.jTable1.setVisible(true);
         this.setVisible(true);
           bandera = 0 ;
           jButton1.setEnabled(true);
         jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/recursos/Pencil_2.png")));
         JOptionPane.showMessageDialog(null,"Actualizado correctamente");
         this.jLabel9.setText("Ingreso de Administrador");
            }
        }catch(Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null,"Error al cargar datos");
        }
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
       String cedula = ""+this.jTable1.getValueAt(this.filaSeleccionada, 4 );
       
       Administrador a = Modelo.consultarAdministrador(cedula);
       
       Modelo.eliminar(a);
        List<Administrador> lista = Modelo.consultarAdministradores();
        this.setVisible(false);
         this.removeAll();
         initComponents();
          for(int i = 0 ; i < lista.size() ; i++){
         
             this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
             this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
             this.jTable1.setValueAt(lista.get(i).getUsuario(), i, 2);
             this.jTable1.setValueAt(lista.get(i).getClave(), i, 3);
             this.jTable1.setValueAt(lista.get(i).getCedula(), i, 4);
             this.jTable1.setValueAt(lista.get(i).getEstado(), i, 5);
         }
        // this.jTable1.setVisible(true);
         this.setVisible(true);
    }//GEN-LAST:event_jButton3ActionPerformed

private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
// TODO add your handling code here:
    
    this.filaSeleccionada = this.jTable1.getSelectedRow(); 
    this.lista.add(this.jTable1.getSelectedRow());
    
    
}//GEN-LAST:event_jTable1MouseClicked

private void jTextField6KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField6KeyReleased
 
    String c = this.jTextField6.getText();
    List<Administrador> lista = Modelo.consultarAdministradoresCoincidencias(c);
        for(int i=0; i< this.jTable1.getRowCount(); i++){
            this.jTable1.setValueAt("", i, 0);
            this.jTable1.setValueAt("",i, 1);
            this.jTable1.setValueAt("", i, 2);
            this.jTable1.setValueAt("", i, 3);
            this.jTable1.setValueAt("",i, 4);
            this.jTable1.setValueAt("", i, 5); 
        }
        for(int i = 0 ; i < lista.size(); i++){
            this.jTable1.setValueAt(lista.get(i).getNombre(), i, 0);
            this.jTable1.setValueAt(lista.get(i).getApellido(), i, 1);
            this.jTable1.setValueAt(lista.get(i).getUsuario(), i, 2);
            this.jTable1.setValueAt(lista.get(i).getClave(), i, 3);
            this.jTable1.setValueAt(lista.get(i).getCedula(), i, 4);
            this.jTable1.setValueAt(lista.get(i).getEstado(), i, 5);
        }
}//GEN-LAST:event_jTextField6KeyReleased

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private recursos.JEImagePanel jEImagePanel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    // End of variables declaration//GEN-END:variables
}
